package com.cx.config;

import org.springframework.web.servlet.LocaleResolver;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @auther: Centaury
 * @Date:2023/3/20 - 03 - 20 - 19:29
 */
public class MyLocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        // 获取参数l
        String language = request.getParameter("l");

        // System.out.println("language==>"+language);
        //没有配制就使用默认值
        Locale aDefault = Locale.getDefault();

        if(!StringUtils.isEmpty(language)){
            String [] split = language.split("_");
            aDefault = new Locale(split[0], split[1]);
        }
        return aDefault;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
